package com.yyk.yykywd

import android.content.Context
import android.graphics.Color
import com.bigkoo.pickerview.builder.OptionsPickerBuilder
import com.bigkoo.pickerview.builder.TimePickerBuilder
import com.bigkoo.pickerview.listener.OnOptionsSelectListener
import com.bigkoo.pickerview.listener.OnTimeSelectListener
import com.bigkoo.pickerview.view.OptionsPickerView
import com.orhanobut.logger.Logger
import kotlinx.android.synthetic.main.activity_modify_meeting_invitation.*
import java.util.*

/**
 * 文件描述：
 * Created by guo on 2019-11-21.
 */
fun showTimePicker(context: Context,
                   showYear: Boolean,
                   showMonth: Boolean,
                   showDay: Boolean,
                   showHour: Boolean,
                   showMinute: Boolean,
                   showSecond: Boolean,
                   startDate: Calendar,
                   endDate: Calendar,
                   pattern: String,
                   mListener: ((String) -> Unit)) {
    //时间选择器
    val pvTime = TimePickerBuilder(context, OnTimeSelectListener { date, v ->
        mListener.invoke(getTime(date, pattern))
    }).setTitleBgColor(Color.WHITE) //标题背景颜色 Night mode
            .setTitleText("选择日期")
            .setSubmitText("确定") //确定按钮文字
            .setSubCalSize(15)
            .setSubmitColor(-0xdededf) //确定文字颜色
            .setCancelText("取消") //取消按钮文字
            .setSubCalSize(15)
            .setCancelColor(-0x888889) //取消文字颜色
            .setDividerColor(-0x282829) //分割线颜色
            .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
            .setContentTextSize(15)
            .setLineSpacingMultiplier(2.5f) // item 间距
            .setLabel("年", "月", "日", "时", "分", "秒")
            .setType(booleanArrayOf(showYear, showMonth, showDay, showHour, showMinute, showSecond))
            .setDate(startDate)
            .setRangDate(startDate, endDate)
            .build()
    pvTime.show()
}

fun showOptionsPicker(context: Context, mListener: ((Int, Int, Int) -> Unit)): OptionsPickerView<Any> {
    val pvOptions = OptionsPickerBuilder(context, OnOptionsSelectListener { options1, options2, options3, v ->
        //返回的分别是三个级别的选中位置
        mListener.invoke(options1, options2, options3)
    })
            .setTitleBgColor(Color.WHITE) //标题背景颜色 Night mode
            .setTitleText("")
            .setSubmitText("确定") //确定按钮文字
            .setSubCalSize(15)
            .setSubmitColor(-0xdededf) //确定文字颜色
            .setCancelText("取消 ") //取消按钮文字
            .setSubCalSize(15)
            .setCancelColor(-0x888889) //取消文字颜色
            .setDividerColor(R.color.gray_d7) //分割线颜色
            .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
            .setContentTextSize(15)
            .isDialog(false) //是否显示为对话框样式
            .setSelectOptions(14, 1, 1) //设置默认选中项
            .setLineSpacingMultiplier(3f) // item 间距
            .isRestoreItem(false) //保留上个选项
            .build<Any>()
    pvOptions.setSelectOptions(0, 0, 0)
    return pvOptions
}
